package io.github.lee.repository.qb.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import androidx.room.Update
import io.github.lee.repository.qb.data.QbSession

@Dao
interface SessionDao {

    @Transaction
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    suspend fun insert(session: QbSession): Long


    @Update
    suspend fun update(session: QbSession): Int

    @Delete
    suspend fun delete(session: QbSession): Int

    @Query("SELECT * FROM t_qb_session WHERE id = :id")
    suspend fun queryById(id: String): QbSession?

    @Query("SELECT * FROM t_qb_session WHERE host = :host")
    suspend fun queryByHost(host: String): QbSession?

    @Query("SELECT * FROM t_qb_session ORDER BY update_time DESC")
    suspend fun queryLast(): QbSession?

}